package com.example.ui.share.adapter;

import java.util.List;
import java.util.Map;

import com.example.huashangapp.R;
import com.example.ui.share.adapter.AroundCircleAdapter.Holder;
import com.example.util.Util;

import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MyCreateCircleAdapter extends BaseAdapter {
	Context mContext;
	private LayoutInflater inflater;
	private List<Map<String, Bitmap>> list;
	private int[] imgArr =new int[]{R.drawable.ar_btn1};
	
	public MyCreateCircleAdapter(Context context,List<Map<String, Bitmap>> gridList){
		mContext = context;
		list=gridList;
		inflater=LayoutInflater.from(mContext);
	}
	
	@Override
	public int getCount() {
		if(list.size()==0){
			return 0;
		}
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.create_circle_gridview_item, null);
			holder = new Holder();
        	holder.img = (ImageView)convertView.findViewById(R.id.create_circle_grid_img);
        	convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
		
		Bitmap bit = null;
		if(list.size()==0){
			holder.img.setBackgroundResource(R.drawable.ar_btn1);
			holder.img.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Util.toast(mContext, "创建圈子");
				}
			});
		}else{
			bit = list.get(position).get("img");
			Drawable dra = new BitmapDrawable(bit);
			holder.img.setBackgroundDrawable(dra);
		}
		holder.img.setScaleType(ImageView.ScaleType.CENTER);
		holder.img.setAdjustViewBounds(true);
		holder.img.setLayoutParams(new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		
		return convertView;
	}
	
	class Holder{
    	ImageView img;
    }

}
